<a href='https://github.com/angular/angular.js/edit/v1.5.x/src/ngMessages/messages.js?message=docs(ngMessages)%3A%20describe%20your%20change...#L271' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.5.8/src/ngMessages/messages.js#L271' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">ngMessages</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - directive in module <a href="api/ngMessages">ngMessages</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p><code>ngMessages</code> is a directive that is designed to show and hide messages based on the state
of a key/value object that it listens on. The directive itself complements error message
reporting with the <code>ngModel</code> $error object (which stores a key/value state of validation errors).</p>
<p><code>ngMessages</code> manages the state of internal messages within its container element. The internal
messages use the <code>ngMessage</code> directive and will be inserted/removed from the page depending
on if they&#39;re present within the key/value object. By default, only one message will be displayed
at a time and this depends on the prioritization of the messages within the template. (This can
be changed by using the <code>ng-messages-multiple</code> or <code>multiple</code> attribute on the directive container.)</p>
<p>A remote template can also be used to promote message reusability and messages can also be
overridden.</p>
<p><a href="api/ngMessages">Click here</a> to learn more about <code>ngMessages</code> and <code>ngMessage</code>.</p>

</div>






<div>
  

  
  <h2>Directive Info</h2>
  <ul>
    
    <li>This directive executes at priority level 0.</li>
    
  </ul>

  
  <h2 id="usage">Usage</h2>
  <div class="usage">
  
    <pre><code class="lang-html">&lt;!-- using attribute directives --&gt;
&lt;ANY ng-messages=&quot;expression&quot; role=&quot;alert&quot;&gt;
  &lt;ANY ng-message=&quot;stringValue&quot;&gt;...&lt;/ANY&gt;
  &lt;ANY ng-message=&quot;stringValue1, stringValue2, ...&quot;&gt;...&lt;/ANY&gt;
  &lt;ANY ng-message-exp=&quot;expressionValue&quot;&gt;...&lt;/ANY&gt;
&lt;/ANY&gt;

&lt;!-- or by using element directives --&gt;
&lt;ng-messages for=&quot;expression&quot; role=&quot;alert&quot;&gt;
  &lt;ng-message when=&quot;stringValue&quot;&gt;...&lt;/ng-message&gt;
  &lt;ng-message when=&quot;stringValue1, stringValue2, ...&quot;&gt;...&lt;/ng-message&gt;
  &lt;ng-message when-exp=&quot;expressionValue&quot;&gt;...&lt;/ng-message&gt;
&lt;/ng-messages&gt;
</code></pre>

  
  </div>
  
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        ngMessages
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a>
      </td>
      <td>
        <p>an angular expression evaluating to a key/value object
                (this is typically the $error object on an ngModel instance).</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        ngMessagesMultiple
        | multiple
        <div><em>(optional)</em></div>
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a>
      </td>
      <td>
        <p>when set, all messages will be displayed with true</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
  


  
  <h2 id="example">Example</h2><p>

<div>
  <plnkr-opener example-path="examples/example-ngMessages-directive"></plnkr-opener>

  <div class="runnable-example"
      path="examples/example-ngMessages-directive"
      name="ngMessages-directive"
      module="ngMessagesExample"
      deps="angular-messages.js"
      animations="true"
      fixBase="true">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;form name=&quot;myForm&quot;&gt;&#10;  &lt;label&gt;&#10;    Enter your name:&#10;    &lt;input type=&quot;text&quot;&#10;           name=&quot;myName&quot;&#10;           ng-model=&quot;name&quot;&#10;           ng-minlength=&quot;5&quot;&#10;           ng-maxlength=&quot;20&quot;&#10;           required /&gt;&#10;  &lt;/label&gt;&#10;  &lt;pre&gt;myForm.myName.$error = {{ myForm.myName.$error | json }}&lt;/pre&gt;&#10;&#10;  &lt;div ng-messages=&quot;myForm.myName.$error&quot; style=&quot;color:maroon&quot; role=&quot;alert&quot;&gt;&#10;    &lt;div ng-message=&quot;required&quot;&gt;You did not enter a field&lt;/div&gt;&#10;    &lt;div ng-message=&quot;minlength&quot;&gt;Your field is too short&lt;/div&gt;&#10;    &lt;div ng-message=&quot;maxlength&quot;&gt;Your field is too long&lt;/div&gt;&#10;  &lt;/div&gt;&#10;&lt;/form&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="script.js"
      language="js"
      type="js">
      <pre><code>angular.module(&#39;ngMessagesExample&#39;, [&#39;ngMessages&#39;]);</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-ngMessages-directive/index.html" name="example-ngMessages-directive"></iframe>
  </div>
</div>


</p>

</div>


